07 / 07

What is the purpose of the alt attribute in an <img> tag ?

Using the alt Attribute in HTML Images

The alt attribute in an <img> tag provides alternative text for an image. It is displayed if the image cannot be loaded and is also read by screen readers, making web content accessible to visually impaired users. The alt text should describe the content or purpose of the image.

Example: Using the alt Attribute
Key Points About the alt Attribute
  1. 1

    The alt attribute provides text shown when an image cannot be loaded.

  2. 2

    It improves accessibility by giving screen readers a description of the image.

  3. 3

    Alt text should be concise and meaningful, describing the image’s content or function.

  4. 4

    For decorative images, an empty alt (alt="") is recommended so screen readers skip it.

  5. 5

    It is an essential part of good SEO, as search engines also use alt text to understand images.